/*
 * Copyright [duowan.com]
 * Web Site: http://www.duowan.com
 * Since 2005 - 2014
 */

package com.duowan.realtime.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.duowan.common.util.page.Page;
import com.duowan.realtime.dao.BloomfilterGroupDao;
import com.duowan.realtime.model.BloomfilterGroup;
import com.duowan.realtime.query.BloomfilterGroupQuery;
import com.duowan.realtime.service.BloomfilterGroupService;


/**
 * [BloomfilterGroup] 的业务操作实现类
 * 
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */
@Service("bloomfilterGroupService")
@Transactional
public class BloomfilterGroupServiceImpl implements BloomfilterGroupService {

	protected static final Logger log = LoggerFactory.getLogger(BloomfilterGroupServiceImpl.class);
	
	//
	// 请删除无用的方法，代码生成器只是为你生成一个架子
	//
	
	private BloomfilterGroupDao bloomfilterGroupDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setBloomfilterGroupDao(BloomfilterGroupDao dao) {
		this.bloomfilterGroupDao = dao;
	}
	
	/** 
	 * 创建BloomfilterGroup
	 **/
	public BloomfilterGroup create(BloomfilterGroup bloomfilterGroup) {
	    Assert.notNull(bloomfilterGroup,"'bloomfilterGroup' must be not null");
	    initDefaultValuesForCreate(bloomfilterGroup);
	    new BloomfilterGroupChecker().checkCreateBloomfilterGroup(bloomfilterGroup);
	    bloomfilterGroupDao.insert(bloomfilterGroup);
	    return bloomfilterGroup;
	}
	
	/** 
	 * 更新BloomfilterGroup
	 **/	
    public BloomfilterGroup update(BloomfilterGroup bloomfilterGroup) {
        Assert.notNull(bloomfilterGroup,"'bloomfilterGroup' must be not null");
        new BloomfilterGroupChecker().checkUpdateBloomfilterGroup(bloomfilterGroup);
        bloomfilterGroupDao.update(bloomfilterGroup);
        return bloomfilterGroup;
    }	
    
	/** 
	 * 删除BloomfilterGroup
	 **/
    public void removeById(int id) {
        bloomfilterGroupDao.deleteById(id);
    }
    
	/** 
	 * 根据ID得到BloomfilterGroup
	 **/    
    public BloomfilterGroup getById(int id) {
        return bloomfilterGroupDao.getById(id);
    }
    
    
    
	/** 
	 * 分页查询: BloomfilterGroup
	 **/      
	@Transactional(readOnly=true)
	public Page<BloomfilterGroup> findPage(BloomfilterGroupQuery query) {
	    Assert.notNull(query,"'query' must be not null");
		return bloomfilterGroupDao.findPage(query);
	}
	
    
	/**
	 * 为创建时初始化相关默认值 
	 **/
    public void initDefaultValuesForCreate(BloomfilterGroup bloomfilterGroup) {
    }
    
    /**
     * BloomfilterGroup的属性检查类,根据自己需要编写自定义检查
     **/
    public class BloomfilterGroupChecker {
        /**可以在此检查只有更新才需要的特殊检查 */
        public void checkUpdateBloomfilterGroup(BloomfilterGroup bloomfilterGroup) {
            checkBloomfilterGroup(bloomfilterGroup);
        }
    
        /**可以在此检查只有创建才需要的特殊检查 */
        public void checkCreateBloomfilterGroup(BloomfilterGroup bloomfilterGroup) {
            checkBloomfilterGroup(bloomfilterGroup);
        }
        
        /** 检查到有错误请直接抛异常，不要使用 return errorCode的方式 */
        public void checkBloomfilterGroup(BloomfilterGroup bloomfilterGroup) {
        	// Bean Validator检查,属性检查失败将抛异常
            //validateWithException(bloomfilterGroup);
            
        	//复杂的属性的检查一般需要分开写几个方法，如 checkProperty1(v),checkProperty2(v)
        }
    }

	@Override
	public List<BloomfilterGroup> getAll() {
		
		return bloomfilterGroupDao.getAll();
	}

	@Override
	public boolean checkBloomFilterExists(String bloomfilterGroup) {
		
		return bloomfilterGroupDao.checkBloomFilterExists(bloomfilterGroup);
	}

	@Override
	public BloomfilterGroup getByBloomfilterGroup(String bloomfilterGroup) {
		
		return bloomfilterGroupDao.getByBloomfilterGroup(bloomfilterGroup);
	}

	@Override
	public List<BloomfilterGroup> getMetaDatas() {
		return bloomfilterGroupDao.getMetaDatas();
	}

}
